Skip to content

Created PAT visual for managing - #338

Merged
yash-pouranik merged 4 commits into
geturbackend:mainfrom
Ayush4958:pat-setting-ui-enabled
Jun 28, 2026
Merged

Created PAT visual for managing #338
yash-pouranik merged 4 commits into
geturbackend:mainfrom
Ayush4958:pat-setting-ui-enabled

Conversation

@Ayush4958

@Ayush4958 Ayush4958 commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

🚀 Pull Request Description

I had created web visual for managing the PAT for user

Screen Recording

Screen.Recording.2026-06-26.151926.mp4

🛠️ Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📝 Documentation update
  • 🎨 UI/UX improvement (Frontend only)
  • ⚙️ Refactor / Chore

🧪 Testing & Validation

Backend Verification:

  • I have run npm test in the backend/ directory and all tests passed.
  • I have verified the API endpoints using Postman/Thunder Client.
  • New unit tests have been added (if applicable).

Frontend Verification:

  • I have run npm run lint in the frontend/ directory.
  • Verified the UI changes on different screen sizes (Responsive).
  • Checked for any console errors in the browser dev tools.

✅ Checklist

  • My code follows the code style of this project.
  • I have performed a self-review of my code.
  • I have commented my code, particularly in hard-to-understand areas.
  • My changes generate no new warnings or errors.
  • I have updated the documentation (README/Docs) accordingly.

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Added a “PAT Visual” section to Settings for verified users, including token listing, expiry/last-used details, generation, one-time reveal/copy, and revocation.
  • Security

    • Personal Access Token actions (create, list, revoke) are now blocked for unverified users with a 403 response.
  • Bug Fixes

    • Improved revocation behavior to fail fast if cache clearing fails, and enhanced UI optimistic updates (including handling “already deleted” during revocation).
    • Clipboard copy now shows a temporary “Copied!” state and cleans up any pending feedback on exit.

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d601443e-cfa6-4050-b27b-a28c5335b56c

📥 Commits

Reviewing files that changed from the base of the PR and between 08b846d and 5a9bb5d.

📒 Files selected for processing (1)
  • apps/web-dashboard/src/components/PATManager.jsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/web-dashboard/src/components/PATManager.jsx

📝 Walkthrough

Walkthrough

Adds verified-user PAT management to Settings, with token listing, creation, one-time reveal/copy, and revocation in the web dashboard. PAT API handlers now reject missing or unverified users before processing token actions.

Changes

PAT Management Flow

Layer / File(s) Summary
API verification guard
apps/dashboard-api/src/controllers/pat.controller.js
createPAT, listPATs, and revokePAT return a 403 AppError for missing or unverified users; revokePAT returns a 503 AppError when Redis cache deletion fails.
PAT fetch and create
apps/web-dashboard/src/components/PATManager.jsx
PATManager adds token loading, create form state, token fetching, create submission, optimistic append, and the one-time raw token reveal state.
PAT revoke and display
apps/web-dashboard/src/components/PATManager.jsx
PATManager adds revocation with duplicate-submit protection, 404 cleanup handling, clipboard copy feedback, the token table, the generate-token modal, the one-time reveal modal, and the revoke confirmation modal.
Settings mount
apps/web-dashboard/src/pages/Settings.jsx
Settings imports PATManager and renders a verified-user PAT Visual section before the Danger Zone section.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant Settings
  participant PATManager
  participant dashboard-api
  participant BrowserClipboard
  User->>Settings: open Settings
  Settings->>PATManager: render PAT Visual for verified user
  PATManager->>dashboard-api: GET /api/user/pats
  dashboard-api-->>PATManager: token list
  User->>PATManager: submit new token label and TTL
  PATManager->>dashboard-api: POST /api/user/pats
  dashboard-api-->>PATManager: created token + rawToken
  PATManager-->>User: show one-time reveal modal
  User->>PATManager: copy rawToken
  PATManager->>BrowserClipboard: navigator.clipboard.writeText(rawToken)
  User->>PATManager: confirm revoke
  PATManager->>dashboard-api: DELETE /api/user/pats/:id
  dashboard-api-->>PATManager: revoke result
  PATManager-->>User: remove token from table
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested labels

type:feature

Suggested reviewers

  • Nitin-kumar-yadav1307
  • yash-pouranik

Poem

A bunny peeked at tokens bright,
Then tucked one secret out of sight.
Verified paws and gentle clicks,
Revokes and reveals and clipboard tricks.
🐰 Hop! The dashboard sparkles tonight.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is related to the main change, indicating a new PAT management visual in the dashboard.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/dashboard-api/src/controllers/pat.controller.js`:
- Around line 83-89: In pat.controller.js, the revocation flow in the controller
that clears `cli:pat:cache:${patToRevoke.tokenHash}` is fire-and-forget, so the
success response can be sent before cache invalidation completes. Update the PAT
revoke handler to `await` the `redis.del()` call, and if it fails or Redis is
unreachable, stop the request and return a 503 via `AppError` instead of
confirming revocation. Keep the database delete and cache clear coordinated in
the same revoke path so the response is only sent after cache invalidation
succeeds.

In `@apps/web-dashboard/src/components/PATManager.jsx`:
- Around line 212-215: The custom token modal overlays in PATManager are missing
dialog semantics for assistive tech. Update the fixed overlay containers used by
the create and other token modals (including the sections controlled by
showCreateModal and the matching modal block later in the component) to expose
role="dialog" and aria-modal, and bind them to a visible heading via an
accessible label such as aria-labelledby on the modal title element. Ensure the
existing heading text like “Generate New Token” is used so screen readers
announce the modal context correctly.
- Around line 180-200: The revoke action in PATManager is not accessible because
the action column header is empty and the button is effectively icon-only.
Update the table header and the revoke control in PATManager so assistive
technologies have an explicit name to announce, using the existing revoke button
handler and revoke state identifiers (such as setRevokeId and the revoke button
markup) to add a clear accessible label.
- Around line 136-142: The copyToClipboard callback in PATManager.jsx sets the
copied state before the clipboard write completes, which can show a false
success. Update copyToClipboard to await navigator.clipboard.writeText(text)
inside try/catch, and only call setCopied(true) after the write succeeds. If the
write fails, do not flip the copied state; keep the existing timer cleanup logic
in place and locate the fix in the copyToClipboard useCallback.

In `@apps/web-dashboard/src/pages/Settings.jsx`:
- Around line 197-198: The PAT access control is only enforced in the UI via
Settings.jsx, so unverified users can still hit the backend PAT APIs. Update the
server-side auth flow by adding an isVerified authorization check in the PAT
route pipeline or a dedicated middleware used by pat.controller methods
createPAT, listPATs, and revokePAT, and ensure authMiddleware propagates
req.user.isVerified so these endpoints reject unverified users consistently.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d7f1cf37-88a6-4710-86f9-082e8b416d1a

📥 Commits

Reviewing files that changed from the base of the PR and between 745d3bd and 3c16263.

📒 Files selected for processing (3)
  • apps/dashboard-api/src/controllers/pat.controller.js
  • apps/web-dashboard/src/components/PATManager.jsx
  • apps/web-dashboard/src/pages/Settings.jsx

Comment thread apps/dashboard-api/src/controllers/pat.controller.js
Comment thread apps/web-dashboard/src/components/PATManager.jsx Outdated
Comment thread apps/web-dashboard/src/components/PATManager.jsx Outdated
Comment thread apps/web-dashboard/src/components/PATManager.jsx Outdated
Comment thread apps/web-dashboard/src/pages/Settings.jsx

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
apps/dashboard-api/src/controllers/pat.controller.js (1)

97-100: 🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

Don't report PAT revocation success when cache invalidation fails.

await redis.del(...) is now synchronous, but this catch still logs and falls through to a 200. If Redis fails here, the DB row is gone while the cached PAT can remain usable until expiry/eviction. Return an AppError (for example 503) instead of confirming revocation.

Proposed fix
         try {
             await redis.del(`cli:pat:cache:${patToRevoke.tokenHash}`);
         } catch (redisErr) {
             console.error("Failed to clear PAT from Redis cache:", redisErr);
+            return next(new AppError(503, "Unable to revoke token right now"));
         }

As per coding guidelines, “Use AppError class for errors.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/dashboard-api/src/controllers/pat.controller.js` around lines 97 - 100,
The PAT revocation flow in pat.controller.js currently logs Redis cache
invalidation failures and still returns success, which can report revocation
even when the cached PAT remains usable. Update the revocation logic around the
redis.del call in the controller method that handles PAT revocation to throw an
AppError instead of falling through when cache clearing fails, and make sure the
failure response uses an appropriate status like 503. Preserve the existing
success path only after both the DB deletion and Redis invalidation complete
successfully.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/dashboard-api/src/controllers/pat.controller.js`:
- Around line 5-8: The new access-control branches in pat.controller.js are
returning AppError through next(), which produces the wrong response envelope
for these endpoints. Update the guards in the PAT controller methods that
currently short-circuit with AppError so they return the standard API shape
directly with success, data, and message fields instead of relying on the global
error handler. Keep the checks in the same controller functions that guard
req.user and req.user.isVerified, and apply the same fix to all three new 403
exits referenced in this diff.

---

Duplicate comments:
In `@apps/dashboard-api/src/controllers/pat.controller.js`:
- Around line 97-100: The PAT revocation flow in pat.controller.js currently
logs Redis cache invalidation failures and still returns success, which can
report revocation even when the cached PAT remains usable. Update the revocation
logic around the redis.del call in the controller method that handles PAT
revocation to throw an AppError instead of falling through when cache clearing
fails, and make sure the failure response uses an appropriate status like 503.
Preserve the existing success path only after both the DB deletion and Redis
invalidation complete successfully.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1d8ef952-9d72-42cd-8a23-b4429457d1d5

📥 Commits

Reviewing files that changed from the base of the PR and between 3c16263 and 336efad.

📒 Files selected for processing (2)
  • apps/dashboard-api/src/controllers/pat.controller.js
  • apps/web-dashboard/src/components/PATManager.jsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/web-dashboard/src/components/PATManager.jsx

Comment on lines +5 to +8
if (!req.user || !req.user.isVerified) {
return next(new AppError(403, 'Forbidden: You must verify your account to access Personal Access Tokens.'));
}

@coderabbitai coderabbitai Bot Jun 26, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

The new 403 branches return the wrong API envelope.

These guards call next(new AppError(...)), and the current global handler serializes that as { success: false, error, message }, not the required { success, data, message }. Since this PR adds three new error exits, it also adds three new contract-breaking responses for these endpoints.

As per coding guidelines, “All API endpoints must return response format: { success: bool, data: {}, message: "" }.”

Also applies to: 55-58, 83-86

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/dashboard-api/src/controllers/pat.controller.js` around lines 5 - 8, The
new access-control branches in pat.controller.js are returning AppError through
next(), which produces the wrong response envelope for these endpoints. Update
the guards in the PAT controller methods that currently short-circuit with
AppError so they return the standard API shape directly with success, data, and
message fields instead of relying on the global error handler. Keep the checks
in the same controller functions that guard req.user and req.user.isVerified,
and apply the same fix to all three new 403 exits referenced in this diff.

Source: Coding guidelines

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes please follow the response type style
@Ayush4958

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yash-pouranik sounds good — the three verified-user guard exits in apps/dashboard-api/src/controllers/pat.controller.js should return the standard API envelope directly, i.e. { success, data, message }, instead of delegating the 403 through next(new AppError(...)).

Once that’s updated in createPAT, listPATs, and revokePAT, this concern should be resolved.

@Ayush4958

Copy link
Copy Markdown
Contributor Author

@yash-pouranik
PR is ready for review

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Comment on lines +5 to +8
if (!req.user || !req.user.isVerified) {
return next(new AppError(403, 'Forbidden: You must verify your account to access Personal Access Tokens.'));
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes please follow the response type style
@Ayush4958

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@Ayush4958

Ayush4958 commented Jun 27, 2026

Copy link
Copy Markdown
Contributor Author

@yash-pouranik
I had applied AppError utility to handle the error in responses
If I goes with res.json() response, It will break the standardize practice

@yash-pouranik

Copy link
Copy Markdown
Member

I literraly forgot
where we have used that or not
I mean total messed up
KOi ni lets merge this then I will audit

@yash-pouranik
yash-pouranik merged commit 030f187 into geturbackend:main Jun 28, 2026
8 checks passed
@Nitin-kumar-yadav1307

Copy link
Copy Markdown
Collaborator

@coderabbitai new files added in this PR and location

@coderabbitai

coderabbitai Bot commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Get PR metadata to identify the base branch for comparison
base_ref=$(gh pr view 338 --json baseRefName --jq '.baseRefName')
echo "BASE_REF=$base_ref"

# Ensure the base branch ref is available locally
git fetch origin "$base_ref" --depth=1 >/dev/null 2>&1 || true

echo
echo "Added files in PR `#338`:"
git diff --name-status "origin/$base_ref...HEAD" | awk '$1=="A" {print $2}'

Length of output: 800


🏁 Script executed:

#!/bin/bash
set -euo pipefail

gh pr view 338 --repo geturbackend/urBackend --json files \
  --jq '.files[] | select(.additions > 0 and .deletions == 0) | [.path] | `@tsv`'

Length of output: 400


🏁 Script executed:

#!/bin/bash
set -euo pipefail

gh pr view 338 --repo geturbackend/urBackend --json files \
  --jq '.files[] | [.path, .status] | `@tsv`'

Length of output: 420


🏁 Script executed:

#!/bin/bash
set -euo pipefail

gh api repos/geturbackend/urBackend/pulls/338/files --paginate \
  --jq '.[] | [.filename, .status] | `@tsv`'

Length of output: 445



@Nitin-kumar-yadav1307 Only 1 new file was added in this PR:

  • apps/web-dashboard/src/components/PATManager.jsx

For clarity, these other changed files are modified, not newly added:

  • apps/dashboard-api/src/controllers/pat.controller.js
  • apps/web-dashboard/src/pages/Settings.jsx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants